package cn.itsource.controller.app;


import cn.dev33.satoken.annotation.SaIgnore;
import cn.itsource.pojo.dto.LocationDto;
import cn.itsource.pojo.dto.WxRegisterDto;

import cn.itsource.pojo.vo.WorkBenchDataVo;
import cn.itsource.result.JSONResult;

import cn.itsource.service.IDriverService;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Tag(name = "司机对象",description = "司机对象")
@RestController
@RequestMapping("/app/driver")
public class AppDriverController {

    @Autowired
    public IDriverService driverService;

    @Operation( summary= "微信注册",description = "微信注册")
    @Parameter(name = "driver",description = "保存的对象",required = true)
    @PostMapping("/wxRegister")
    @SaIgnore
    public JSONResult wxRegister(@RequestBody @Valid WxRegisterDto dto){
        driverService.wxRegister(dto);
        return JSONResult.success();
    }

    @Operation( summary= "加载工作台数据",description = "加载工作台数据")
    @PostMapping("/workbenchData")
    public JSONResult selectWorkbenchDate(){
        WorkBenchDataVo workBenchDataVo = driverService.selectWorkbenchDate();
        return JSONResult.success(workBenchDataVo);
    }


    @Operation( summary= "开启接单",description = "开启接单")
    @PostMapping("/online")
    public JSONResult online(){
        driverService.online();
        return JSONResult.success();
    }

    @Operation( summary= "停止接单",description = "停止接单")
    @PostMapping("/offline")
    public JSONResult offline(){
        driverService.offline();
        return JSONResult.success();
    }

    @Operation( summary= "缓存司机坐标到Redis中的GEO",description = "缓存司机坐标到Redis中的GEO")
    @PostMapping("/cache/location/geo")
    public JSONResult cacheLocationGeo(@RequestBody @Valid LocationDto dto){
        driverService.cacheLocationGeo(dto);
        return JSONResult.success();
    }
}
